package dfl.bysj.controller;


import dfl.bysj.entity.Floor;
import dfl.bysj.entity.Seat;
import dfl.bysj.entity.SeatState;
import dfl.bysj.handler.NoAuth;
import dfl.bysj.result.R;
import dfl.bysj.service.FloorService;
import dfl.bysj.service.SeatService;
import dfl.bysj.service.SeatStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author DFL
 * @since 2022-04-26
 */
@RestController
@RequestMapping("/seat")
public class SeatController {

    SeatService seatService;

    RedisTemplate redisTemplate;

    private FloorService floorService;

    private SeatStateService seatStateService;


    @Autowired
    public void setSeatStateService(SeatStateService seatStateService) {
        this.seatStateService = seatStateService;
    }

    @Autowired
    public void setFloorService(FloorService floorService) {
        this.floorService = floorService;
    }

    @Autowired
    public void setRedisTemplate(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Autowired
    public void setSeatService(SeatService seatService) {
        this.seatService = seatService;
    }

    @NoAuth
    @GetMapping("/count")
    public R count(){
        return R.ok().data("seatCount",seatService.getSeatCount());
    }
    @NoAuth
    @GetMapping("/list")
    public R list(){
        return R.ok().data("seatList",seatService.getAllSeats());
    }

    @NoAuth
    @GetMapping("/floor/list")
    public R floor_list(Integer floId){
        if(floId==0){
            return R.ok().data("seatList",seatService.getAllSeats());
        }

        return R.ok().data("seatList",seatService.getSeatByFloId(floId));
    }

    @GetMapping("/seaNum_floorNum")
    public R seaNum(Integer sea_id){
        Seat seat=seatService.getSeaNumBySeaId(sea_id);
        Floor floor=floorService.getFloorByfloId(seat.getFloId());
        HashMap<String,Integer> map=new HashMap<>();
        map.put("seaNum", seat.getSeaNum());
        map.put("floNum", floor.getFloNum());
        return R.ok().data("map",map);
    }
    @GetMapping("/seaNum_floorNum_seaStaId")
    public R seatFlo(Integer seaStaId){
        SeatState seatState=seatStateService.getById(seaStaId);
        Seat seat=seatService.getSeaNumBySeaId(seatState.getSeaId());
        Floor floor=floorService.getFloorByfloId(seat.getFloId());
        HashMap<String,Integer> map=new HashMap<>();
        map.put("seaNum", seat.getSeaNum());
        map.put("floNum", floor.getFloNum());
        return R.ok().data("map",map);
    }

    /**
     * 将链接存储到数据库
     * @param fileID
     * @return
     */
    @GetMapping("/upload")
    public R upload(Integer seaId,String fileID){
        seatService.updateSeatPic(seaId,fileID);
        return R.ok();
    }

}

